package controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import entity.Livecommerce;
import service.LivecommerceService;

import java.util.List;

@Controller

public class LivecommerceController {
    @Autowired
    private LivecommerceService livecommerceService;

    @RequestMapping("/list")
    public String list(HttpServletRequest req, Model model) {
        List<Livecommerce> list = livecommerceService.selectPageList();
        model.addAttribute("list", list);
        return "list";
    }

    @RequestMapping(value = "/add")
    public String add(Livecommerce livecommerce) {
        return "add";
    }

    @RequestMapping("/save")
    public String save(Livecommerce livecommerce) {
        int num = livecommerceService.add(livecommerce);
        if(num>0){
            System.out.println("新增成功");
        }
        return "redirect:/list";
    }

    @RequestMapping("/detail")
    public String showUserDetail(@RequestParam("id") int id, Model model) {
        Livecommerce user = livecommerceService.findById(id);
        model.addAttribute("user", user);
        return "userDetail";
    }
}
